package com.salt.common.utils;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;

public class Format {
	
	public static Double number(double num) {
		BigDecimal bg = new BigDecimal(num);
		return bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
	}
	
	public static Double numberThree(double num) {
		 BigDecimal bg = new BigDecimal(num);
		 return  bg.setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue();
	}
	
	public static Double numberFour(double num) {
		 BigDecimal bg = new BigDecimal(num);
		 return  bg.setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue();
	}
	
	public static double numberDouble(double num) {
		 BigDecimal bg = new BigDecimal(num);
		 return  bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
	}
	
	public static String formatNumber(double num) {
		DecimalFormat df = new DecimalFormat("#.00");
        return df.format(num);
	}
	
	public static String formatNumber1(double num) {
		DecimalFormat df = new DecimalFormat("0.00");
        return df.format(num);
	}
	
	public static String formatThreeStr(double num) {
		DecimalFormat df = new DecimalFormat("#.000");
        return df.format(num);
	}
	
	public static String formatThreeStr1(double num) {
		DecimalFormat df = new DecimalFormat("0.000");
        return df.format(num);
	}
	
	public static String formatNumberPercent(double num) {
		DecimalFormat df = new DecimalFormat("0.00%");
        return df.format(num);
	}

	
	public static double formatNum(double num) {
		double number = 0;
		DecimalFormat df = new DecimalFormat("#.00");
		 df.setRoundingMode(RoundingMode.HALF_UP);
		 String n = df.format(num);
		 if (n != null && n != "") {
			 number = Double.parseDouble(n);
		 }
        return number;
	}
	
	public static float formatFloatNum(float num) {
		float number = 0;
		DecimalFormat df = new DecimalFormat("#.00");
		 df.setRoundingMode(RoundingMode.HALF_UP);
		 String n = df.format(num);
		 if (n != null && n != "") {
			 number = Float.parseFloat(n.trim());
		 }
        return number;
	}
	
	public static float floatNum(float num) {
		float number = 0;
		DecimalFormat df = new DecimalFormat("#.0000");
		 df.setRoundingMode(RoundingMode.HALF_UP);
		 String n = df.format(num);
		 if (n != null && n != "") {
			 number = Float.parseFloat(n.trim());
		 }
        return number;
	}
	
}
